#include "pch.hpp"

#include "Clouds.h"

static sf::Randomizer random;

void Clouds::load()
{
	clouds[0].LoadFromFile("data/chmury1.png");
	clouds[1].LoadFromFile("data/chmury2.png");

	sprites[0].SetImage(clouds[0]);
	sprites[0].SetCenter(clouds[0].GetWidth()/2.0f, clouds[0].GetHeight()/2.0f);
	sprites[1].SetImage(clouds[1]);
	sprites[1].SetCenter(clouds[1].GetWidth()/2.0f, clouds[1].GetHeight()/2.0f);

	curr_cloud_id = 0;
	clouds_time = 0;

	random.SetSeed(time(0));

	position = sf::Vector2f(1000000, 100000);
}

void Clouds::step()
{
	clouds_time -= 1.0f/60.0f;

	if(sfm::Length(position - sf::Vector2f(0, 768/2.0f)) > 1200)
	{
		clouds_time = random.Random(20, 30);
		float angle = random.Random(0, 360);
		sf::Vector2f vec(707, -707);
		position = vec + sf::Vector2f(0, 768/2.0f);
		sfm::Normalize(vec);
		const float speed = 100;
		velocity = -sf::Vector2f(vec.x*speed, vec.y*speed);

		curr_cloud_id = rand()%2;
	}

	position += velocity*1.0f/60.0f;
}

void Clouds::draw()
{
	sprites[curr_cloud_id].SetPosition(position);
	app.Draw(sprites[curr_cloud_id]);
}